package com.app.micaihu.bean.news;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.configure.TypeConstant;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.micaihu.listener.AutoHeightControllerListener;
import com.app.utils.util.image.LoadImageUtils;


/**
 * 文章大图(适配推荐列表的 文章 图集 视频)
 * Created by linkai on 2016/7/18.
 */
public class ViewNewsBigImg extends ViewNewsParent {

    public CustomImageView bigImg;
    public ImageView videoImg;
    public TextView picNum;
    private AutoHeightControllerListener autoHeightControllerListener;

    public ViewNewsBigImg(View convertView) {
        initView(convertView);
    }

    public void initView(View convertView) {
        super.initView(convertView);
        this.bigImg = (CustomImageView) convertView.findViewById(R.id.item_large_image);
        this.videoImg = (ImageView) convertView.findViewById(R.id.item_video_pic);
        this.picNum = (TextView) convertView.findViewById(R.id.item_picnum);
        autoHeightControllerListener = new AutoHeightControllerListener(this.bigImg,4.35f,1.58f);
        convertView.setTag(this);
    }

    /**
     * 加载数据
     * @param newsEntity
     */
    public void loadData(NewsEntity newsEntity){
        super.loadData(newsEntity);

        if(TypeConstant.PIC_NORMAL.equals(newsEntity.getArticleType())
                || TypeConstant.PIC_TOPIC.equals(newsEntity.getArticleType())
                || TypeConstant.SHOP_ALI_PIC.equals(newsEntity.getArticleType())){
            //如果是图集
            LoadImageUtils.getInstance().loadWifiImage(this.bigImg, newsEntity.getArticleThumb()[0]);
            if(this.bigImg.getAspectRatio() != 1.95f){
                this.bigImg.setAspectRatio(1.95f);
            }
            if(this.videoImg.getVisibility() == View.VISIBLE){
                this.videoImg.setVisibility(View.GONE);
            }
            this.picNum.setText(newsEntity.getPicNum()+"图");
            if(this.picNum.getVisibility() == View.GONE){
                this.picNum.setVisibility(View.VISIBLE);
            }
        }else if(TypeConstant.VIDEO_WEB.equals(newsEntity.getArticleType())
                || TypeConstant.VIDEO_NORMAL.equals(newsEntity.getArticleType())
                || TypeConstant.VIDEO_ORIGINAL.equals(newsEntity.getArticleType())){
            //如果是视频
            LoadImageUtils.getInstance().loadWifiImage(this.bigImg, newsEntity.getArticleThumb()[0]);
            if(this.bigImg.getAspectRatio() != 1.58f){
                this.bigImg.setAspectRatio(1.58f);
            }
            if(this.videoImg.getVisibility() == View.GONE){
                this.videoImg.setVisibility(View.VISIBLE);
            }
            if(this.picNum.getVisibility() == View.VISIBLE){
                this.picNum.setVisibility(View.GONE);
            }
        }else if(TypeConstant.AD.equals(newsEntity.getArticleType())){
            //如果是广告
            LoadImageUtils.getInstance().loadWifiImage(this.bigImg, newsEntity.getArticleThumb()[0],autoHeightControllerListener);
            if(this.videoImg.getVisibility() == View.VISIBLE){
                this.videoImg.setVisibility(View.GONE);
            }
            if(this.picNum.getVisibility() == View.VISIBLE){
                this.picNum.setVisibility(View.GONE);
            }
        }else{
            //默认
            LoadImageUtils.getInstance().loadWifiImage(this.bigImg, newsEntity.getArticleThumb()[0]);
            if(this.bigImg.getAspectRatio() != 1.58f){
                this.bigImg.setAspectRatio(1.58f);
            }
            if(this.videoImg.getVisibility() == View.VISIBLE){
                this.videoImg.setVisibility(View.GONE);
            }
            if(this.picNum.getVisibility() == View.VISIBLE){
                this.picNum.setVisibility(View.GONE);
            }
        }
    }

    /**
     * 加载数据
     * @param newsEntity
     * @param matchStr
     */
    public void loadData(NewsEntity newsEntity, String matchStr){
        loadData(newsEntity);
        super.matchTitle(newsEntity.getArticleTitle(), matchStr);
    }

}
